﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;

namespace Collection.Web.QueryHandler
{
	/// <summary>
	/// 一般请求模块的基类
	/// </summary>
	public class BaseHandler : IHttpHandler
	{
		/// <summary>
		/// Http请求对象信息
		/// </summary>
		private HttpRequest request;

		/// <summary>
		/// Http请求对象信息
		/// </summary>
		public HttpRequest Request
		{
			get { return request; }
		}

		/// <summary>
		/// Http响应对象信息
		/// </summary>
		private HttpResponse response;

		public HttpResponse Response
		{
			get { return response; }
		}

		/// <summary>
		///Http服务对象
		/// </summary>
		private HttpServerUtility server;

		/// <summary>
		/// Http服务对象
		/// </summary>
		public HttpServerUtility Server
		{
			get { return server; }
			set { server = value; }
		}

		/// <summary>
		/// 当前Http请求的Session对象
		/// </summary>
		private HttpSessionState session;

		/// <summary>
		/// 当前Http请求的Session对象
		/// </summary>
		public HttpSessionState Session
		{
			get { return session; }
		}

		/// <summary>
		/// Http上下文对象
		/// </summary>
		private HttpContext context;

		/// <summary>
		/// Http上下文对象
		/// </summary>
		public HttpContext Context
		{
			get { return context; }
		}

		/// <summary>
		/// Http请求处理第一步
		/// </summary>
		/// <param name="context">当前请求上下文</param>
		public void ProcessRequest(HttpContext context)
		{
			this.context = context;
			this.request = context.Request;
			this.response = context.Response;
			this.server = context.Server;
			this.session = context.Session;
			if (this.request.HttpMethod.Equals("GET"))
			{
				this.HttpGetProcess();
			}
			else if (this.request.HttpMethod.Equals("POST"))
			{
				this.HttpPostProcess();
			}
		}

		/// <summary>
		/// Get请求处理
		/// </summary>
		public virtual void HttpGetProcess()
		{ 
			//子类来实现
		}

		/// <summary>
		/// Post请求处理
		/// </summary>
		public virtual void HttpPostProcess()
		{
			//子类来实现
		}

		/// <summary>
		/// 当前对象实例是否可用
		/// </summary>
		public virtual bool IsReusable
		{
			get { return false; }
		}
	}
}